var today=null;
var app_path=$t('path')[0].value;
window.onload=function(){
	initElementValues();
	showTodayOriginalTasks();
	showTodayReviewTasks();
	//attachEvents();
};

function initElementValues(){
	getToday();
	$('execute_date').value=today;
}

function attachEvents(){
	$('execute_date').onclick=function(){
		MyCalendar.SetDate(this);
	};
	$('btnAddTask').onclick=function(){
		var oTaskName=$('task_name');
		if(oTaskName.value.length===0){
			alert('请输入任务名称！');
			oTaskName.focus();
			return;
		}
		var oExecuteDate=$('execute_date');
		if(oExecuteDate.value.length===0){
			alert('请选择执行日期！');
			oExecuteDate.focus();
			return;
		}
		var order='<order bo="com.whstudio.task.TaskBO" method="doAddOriginalTask" task_name="'+$('task_name').value+'" execute_date="'+$('execute_date').value+'"><![CDATA['+$('task_content').value+']]></order>';
		sendRequest(app_path+'/sole',order,function(request){
			var root=request.responseXML.documentElement;
			var flag=root.getAttribute('flag');
			if(flag<0){
				alert(root.firstChild.nodeValue);
			}
		},false,'POST');
	};
}

function showTodayOriginalTasks(){
	sendRequest(app_path+'/sole','<order bo="com.whstudio.task.TaskBO" method="doQueryTodayOriginalTask"/>',function(request){
		var response=request.responseXML;
		var root=response.documentElement;
		alert(root.xml);
		var flag=root.getAttribute('flag');
		if(flag<0){
			alert(root.firstChild.nodeValue);
			return false;
		}
		var parameters={
			'rootContainer':$('container'),
			'container':$('original_tasks'),
			'currentDisplay':arrays.homeBlockArray,
			'responseXML':response,
			'template':{'title':template['original_tasks_title'],'row':template['original_tasks_list'],'detail':template['original_tasks_detail']},
			'itemMap':maps['itemMapTask'],
			'ifMutiPage':true
		};
		var pager=new AjaxPager(parameters);
		pager.rowsPerPage=10;
		pager.returnFunction=function(){
			//hide('original_tasks');
			show(arrays.homeBlockArray);
			return false;
		};
		pager.render();
	},false,'POST');
}

function showTodayReviewTasks(){
	sendRequest(app_path+'/sole','<order bo="com.whstudio.task.TaskBO" method="doQueryTodayReviewTask"/>',function(request){
		var response=request.responseXML;
		var root=response.documentElement;
		var flag=root.getAttribute('flag');
		if(flag<0){
			alert(root.firstChild.nodeValue);
			return false;
		}
		var parameters={
			'rootContainer':$('container'),
			'container':$('review_tasks'),
			'currentDisplay':arrays.homeBlockArray,
			'responseXML':response,
			'template':{'title':template['original_tasks_title'],'row':template['original_tasks_list'],'detail':template['original_tasks_detail']},
			'itemMap':maps['itemMapTask'],
			'ifMutiPage':true
		};
		var pager=new AjaxPager(parameters);
		pager.rowsPerPage=10;
		pager.returnFunction=function(){
			//hide('review_tasks');
			show(arrays.homeBlockArray);
			return false;
		};
		pager.render();
	},false,'POST');
}

function getToday(){
	sendRequest(app_path+'/sole','<order bo="com.whstudio.task.TaskBO" method="doQueryTodayDate"/>',function(request){
		today=request.responseXML.documentElement.firstChild.nodeValue;
	},false,'POST');
}
